class Solution {
    public boolean isValidSudoku(char[][] board) {
        List<Set<Character>> list = new ArrayList<>();
        for (int i = 0; i < 27; i++) {
            list.add(new HashSet<>());
        }
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                if (board[i][j] == '.') {
                    continue;
                }
                if (list.get(i).contains(board[i][j])) {
                    return false;
                }
                list.get(i).add(board[i][j]);
                if (list.get(9 + j).contains(board[i][j])) {
                    return false;
                }
                list.get(9 + j).add(board[i][j]);
                if (list.get(18 + i / 3 * 3 + j / 3).contains(board[i][j])) {
                    return false;
                }
                list.get(18 + i / 3 * 3 + j / 3).add(board[i][j]);
            }
        }
        return true;
    }
}